package com.example.testdbsearchform;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomArrayAdapter extends ArrayAdapter<Product> {

	private final Context context;
	private final List<Product> values;
	
	static class ViewHolder {
		public TextView title_list;
		public TextView categoty_list;
		public TextView date_list;
		
	}

	public CustomArrayAdapter(Context context, List<Product> values) {
		super(context, R.layout.activity_list_layout, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.activity_list_layout, parent,
					false);

			ViewHolder viewHolder = new ViewHolder();
			viewHolder.title_list = (TextView) rowView.findViewById(R.id.title_list);
			viewHolder.categoty_list = (TextView) rowView.findViewById(R.id.categoty_list);
			viewHolder.date_list = (TextView) rowView.findViewById(R.id.date_list);
			rowView.setTag(viewHolder);

		}

		ViewHolder holder = (ViewHolder) rowView.getTag();
		Product event = values.get(position);
		holder.title_list.setText(event.getName());
		holder.categoty_list.setText(event.getCategory().getName());
		//holder.categoty_list.setText(Long.toString(event.getDate().getTime()));
		
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
		Date date = event.getDate();
		holder.date_list.setText(sdf.format(date));
		
		return rowView;
	}

}
